//
//  SettingDataCenter.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/16.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "SettingDataCenter.h"

@implementation SettingDataCenter

- (void)uploadAvatar:(UIImage *)image complation:(void (^)(id, NSString *))complation
{
    
    UserModel *user = [UserManager fetchUserInfo];
    NSDictionary *param = @{
                            @"user":[NSNumber numberWithInteger:user.userId],
                            @"imagebase":[UIImage imageToBase64String:image],
                            };
    [HttpRequest POSTRequest:UploadAvatar WithParams:param WithSuccess:^(id responseOjbect) {
        ZLog(@"%@",responseOjbect);
        if ([[responseOjbect objectForKey:@"code"] integerValue] == 1) {
            complation([responseOjbect objectForKey:@"data"],nil);
        }else{
            complation(nil,[responseOjbect objectForKey:@"message"]);
        }
        
    } WithFail:^(NSError *error) {
        complation(nil,@"服务器异常");
    }];
}

- (void)uploadUsername:(NSString *)username complation:(void (^)(NSString *, NSString *))complation
{
    UserModel *user = [UserManager fetchUserInfo];
    NSDictionary *param = @{
                            @"user":[NSNumber numberWithInteger:user.userId],
                            @"username":username,
                            };
    [HttpRequest POSTRequest:MUsername WithParams:param WithSuccess:^(id responseOjbect) {

        if ([[responseOjbect objectForKey:@"code"] integerValue] == 1) {
            complation([[responseOjbect objectForKey:@"data"] objectForKey:@"username"],nil);
        }else{
            complation(nil,[responseOjbect objectForKey:@"message"]);
        }
        
    } WithFail:^(NSError *error) {
        complation(nil,@"服务器异常");
    }];
}

- (void)uploadSign:(NSString *)sign complation:(void (^)(NSString *, NSString *))complation
{
    UserModel *user = [UserManager fetchUserInfo];
    NSDictionary *param = @{
                            @"user":[NSNumber numberWithInteger:user.userId],
                            @"sign":sign,
                            };
    [HttpRequest POSTRequest:MSign WithParams:param WithSuccess:^(id responseOjbect) {

        if ([[responseOjbect objectForKey:@"code"] integerValue] == 1) {
            complation([[responseOjbect objectForKey:@"data"] objectForKey:@"sign"],nil);
        }else{
            complation(nil,[responseOjbect objectForKey:@"message"]);
        }
        
    } WithFail:^(NSError *error) {
        complation(nil,@"服务器异常");
    }];
}

- (void)uploadAddress:(NSString *)sign complation:(void (^)(NSString *, NSString *))complation
{
    UserModel *user = [UserManager fetchUserInfo];
    NSDictionary *param = @{
                            @"user":[NSNumber numberWithInteger:user.userId],
                            @"address":sign,
                            };
    [HttpRequest POSTRequest:MAddress WithParams:param WithSuccess:^(id responseOjbect) {

        if ([[responseOjbect objectForKey:@"code"] integerValue] == 1) {
            complation([[responseOjbect objectForKey:@"data"] objectForKey:@"address"],nil);
        }else{
            complation(nil,[responseOjbect objectForKey:@"message"]);
        }
        
    } WithFail:^(NSError *error) {
        complation(nil,@"服务器异常");
    }];
}

- (void)uploadSex:(NSInteger)sex complation:(void (^)(NSString *, NSString *))complation
{
    UserModel *user = [UserManager fetchUserInfo];
    NSDictionary *param = @{
                            @"user":[NSNumber numberWithInteger:user.userId],
                            @"sex":[NSNumber numberWithInteger:sex],
                            };
    [HttpRequest POSTRequest:MSex WithParams:param WithSuccess:^(id responseOjbect) {
        if ([[responseOjbect objectForKey:@"code"] integerValue] == 1) {
            complation([[responseOjbect objectForKey:@"data"] objectForKey:@"sex"],nil);
        }else{
            complation(nil,[responseOjbect objectForKey:@"message"]);
        }
    } WithFail:^(NSError *error) {
        complation(nil,@"服务器异常");
    }];
}

@end
